﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ZetaPrints.ZetaClient.Data.Repository.Linq
{
    public partial class OrderFileDetail
    {
        /// <summary>
        /// Gets the formated file path for use 
        /// on normal file system stuff
        /// </summary>
        public string FilePath
        {
            get
            {
                string filePath = string.Empty;

                if (LocalPath != null)
                {
                    if (LocalPath.Length > 0)
                    {
                        string fileName = LocalPath.ToLower();

                        string localPath = LocalPath;

                        ZetaClientConfiguration zetaClientConfiguration = new ZetaClientConfiguration();

                        /// if this is located on the default directory we need to add the whole
                        /// path to it. Also this rule is null if the download root directory 
                        /// has an specific path.
                        if ((localPath.StartsWith(zetaClientConfiguration.DownloadRootDirectory)) &&
                            ((!zetaClientConfiguration.DownloadRootDirectory.Contains(":") ||
                             (!zetaClientConfiguration.DownloadRootDirectory.StartsWith(@"\\")))))
                        {
                            string currentDirectory = Assembly.GetExecutingAssembly().Location;

                            currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf('\\'));

                            localPath = currentDirectory + @"\" + localPath;
                        }

                        filePath = localPath;
                    }
                }

                return filePath;
            }
        }
        /// <summary>
        /// Gets the file name of the ORderFileDetail
        /// </summary>
        public string FileName
        {
            get
            {
                string fileName = string.Empty;

                if (LocalPath != null)
                {
                    if (LocalPath.Length > 0)
                    {
                        fileName = LocalPath.Substring(LocalPath.LastIndexOf('\\') + 1);
                    }
                }
                return fileName;
            }
        }
    }
}
